﻿namespace Devonline.Entity;

/// <summary>
/// 个人信息, 字符串主键的默认实现
/// </summary>
//[Cacheable]
[Table("personal"), DisplayName("个人信息")]
public class Personal : Personal<string>, IIdentity, IEntitySet, IEntitySetWithCreate, IEntitySetWithCreateAndUpdate
{
    /// <summary>
    /// 所在区域
    /// </summary>
    public virtual Region? Region { get; set; }
    /// <summary>
    /// 身份证
    /// </summary>
    public virtual IdCard? IdCard { get; set; }
    /// <summary>
    /// 附加信息
    /// </summary>
    public virtual ICollection<PersonalAdditional>? Additionals { get; set; }
    /// <summary>
    /// 通用附件集合, NotMapped Attachments 用于记录实体对象上上传的附件
    /// </summary>
    [NotMapped]
    public virtual ICollection<Attachment>? Attachments { get; set; }
}

/// <summary>
/// 个人附加信息
/// </summary>
[Table("personal_additional"), DisplayName("个人附加信息")]
public class PersonalAdditional : PersonalAdditional<string>, IAdditional, IEntitySet, IEntitySetWithCreate
{
    public virtual Personal? Additional { get; set; }
}

/// <summary>
/// 个人信息
/// 业务关联的用户个人信息, 用于和用户认证和授权信息隔离
/// 个人信息和用户是一对一关系, 没有字段相关指向, 也没有外键直接关联, 他们的主键是同一个值
/// </summary>
[Table("personal"), DisplayName("个人信息")]
public abstract class Personal<TKey> : Identity<TKey>, IIdentity<TKey>, IEntitySet<TKey>, IEntitySetWithCreate<TKey>, IEntitySetWithCreateAndUpdate<TKey> where TKey : IConvertible
{
    /// <summary>
    /// 性别
    /// </summary>
    [Column("gender", TypeName = "VARCHAR(8)"), DisplayName("性别"), Required, Excel(Size = AppSettings.DEFAULT_EXCEL_COLUMN_WIDTH)]
    public virtual Gender Gender { get; set; }
    /// <summary>
    /// 年龄
    /// </summary>
    [Column("age"), DisplayName("年龄"), Excel]
    public virtual int? Age { get; set; }
    /// <summary>
    /// 电话
    /// </summary>
    [Column("phone_number"), MaxLength(256), DisplayName("电话"), Unique, Excel(Size = AppSettings.UNIT_TWO * AppSettings.UNIT_TEN)]
    public virtual string? PhoneNumber { get; set; }
    /// <summary>
    /// 邮箱地址
    /// </summary>
    [Column("email"), MaxLength(256), DisplayName("邮箱"), Excel(Size = AppSettings.UNIT_TWO * AppSettings.UNIT_TEN)]
    public virtual string? Email { get; set; }
    /// <summary>
    /// 地址
    /// </summary>
    [Column("address"), DisplayName("地址"), MaxLength(256), Excel]
    public virtual string? Address { get; set; }
    /// <summary>
    /// 地区, 所在区域
    /// </summary>
    [Column("region_id"), DisplayName("所在区域编号"), MaxLength(36), Excel]
    public virtual TKey? RegionId { get; set; }
    /// <summary>
    /// 身份证编号
    /// </summary>
    [Column("id_card_id"), DisplayName("身份证编号"), MaxLength(36), Excel]
    public virtual TKey? IdCardId { get; set; }
}

/// <summary>
/// 个人附加信息
/// </summary>
[Table("personal_additional"), DisplayName("个人附加信息")]
public abstract class PersonalAdditional<TKey> : Additional<TKey>, IAdditional<TKey>, IEntitySet<TKey>, IEntitySetWithCreate<TKey> where TKey : IConvertible { }